// 引入mock
import Mock from "mockjs"

// 定义登录接口
Mock.mock("/login", "post", (config) => {
    // 数据处理返回
    console.log(config)
    // 获取前端传过来的参数
    let { name, pwd } = JSON.parse(config.body)
    let token = '' //
    let role = ''
    if (name == '华年' && pwd == '123456') {
        token = 'huanian---token---123'
        role = '管理员'
    } else if (name == 'user' && pwd == '123456') {
        token = 'uset---token---123'
        role = '普通用户'
    } else if (name == '小月月' && pwd == '123456') {
        token = 'uset---token---123'
        role = '普通用户'
    } else {
        return {
            code: 500,
            msg: '账户不存在',
            data: {

            }
        }
    }
    return {
        code: 200,
        msg: '登录成功',
        data: {
            token: token,
            role: role
        }
    }
})
// 定义角色接口，根据不同的role 返回不同的路由菜单

Mock.mock("/getPress", "post", (config) => {
    let { role } = JSON.parse(config.body)
    if (role == '管理员') {
        return {
            code: 200,
            msg: '成功',
            data: [
                {
                    path: 'shenpi', //审批管理
                    meta: {
                        title: '审批管理',
                        icon: 'el-icon-bangzhu'
                    },
                    name: 'Shenpi'  //componet
                },
                {
                    path: 'qingjia', //请假审批
                    meta: {
                        title: '请假审批',
                        icon: 'el-icon-bangzhu'
                    },
                    name: 'Qingjia'  //componet
                }, {
                    path: 'woqingjia', //我要请假
                    meta: {
                        title: '我要请假',
                        icon: 'el-icon-bangzhu'
                    },
                    name: 'Woqingjia'  //componet
                }
            ]
        }
    } else if (role == '普通用户') {
        return {
            code: 200,
            msg: '成功',
            data: [{
                path: 'woqingjia', //我要请假
                meta: {
                    title: '我要请假',
                    icon: 'el-icon-bangzhu'
                },
                name: 'Woqingjia'  //componet
            }
            ]
        }
    }
})